/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
  <file> uls_type.h </file>
  <brief>
    A common file for all the ULS sources.
    This file is part of ULS, Unified Lexical Scheme.
  </brief>
  <author>
    Stanley J. Hong <babel96@gmail.com>, August 2011.
  </author>
*/

#ifndef __ULS_TYPE_H__
#define __ULS_TYPE_H__

#include "uls_config.h"
#include "uls_const.h"

#ifdef HAVE_LIBPTHREAD
#include <pthread.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if __BYTE_ORDER == __LITTLE_ENDIAN
#define ULS_LITTLE_ENDIAN 
#elif __BYTE_ORDER == __BIG_ENDIAN
#define ULS_BIG_ENDIAN 
#endif

#define ULS_FALSE       0
#define ULS_TRUE        1

#define ULS_FAIL        0
#define ULS_SUCCESS     1

#define ULS_FILENAME_MAXSIZ  63

#define ULS_LINEBUFF_SZ  256
#define ULS_LINEBUFF_SIZ ULS_LINEBUFF_SZ 

#define MAX_COMMAND_LINE 128
#define ULS_FILEPATH_DELIM '/'

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))

#define uls_dim(A) (sizeof(A)/sizeof(A[0]))
#define uls_roundup(A,B)  (((A) + (B) - 1) & (~((B) - 1)))
#define uls_streql(a,b)     (strcmp((const char*)(a),(const char*)(b))==0)

#ifdef WIN32
typedef int   uls_int32;
typedef long long  uls_int64;
typedef unsigned int   uls_uint32;
typedef unsigned long long  uls_uint64;
#else
typedef int   uls_int32;
typedef long long  uls_int64;
typedef unsigned int   uls_uint32;
typedef unsigned long long  uls_uint64;
#endif

typedef uls_uint32    uls_flags_t;
typedef unsigned char uls_char_t;
typedef unsigned char uls_byte_t;
typedef uls_uint32    uls_uch_t;

typedef struct _csz_str csz_str_t;
typedef struct _uls_version uls_version_t;
typedef struct _uls_literal uls_literal_t;
typedef struct _uls_token uls_token_t;
typedef struct _istr_commtype istr_commtype_t;
typedef struct _istr_quotetype istr_quotetype_t;
typedef struct _uls_istream uls_istream_t;
typedef struct _istr_context istr_context_t;
typedef struct _istr_fd istr_fd_t;
typedef struct _uls_tokdef uls_tokdef_t;
typedef struct _uls_kwtable uls_kwtable_t;
typedef struct _uls_kwrd_stat uls_kwrd_stat_t;
typedef struct _ulc_header ulc_header_t;
typedef struct _ulf_header ulf_header_t;
typedef struct _uls_lex uls_lex_t;
typedef struct _uls_stream uls_stream_t;

typedef int (*uls_gettok_t)(uls_lex_t* uls);
typedef int (*istr_filler_t)(uls_istream_t* istr,
	uls_char_t** p_line, uls_literal_t* lits, int* n_lits);
typedef int (*istr_analyzer_t)(istr_fd_t *fd_src, uls_char_t* quote_str,
	csz_str_t *ss_dst, uls_literal_t* lit, int* p_lno);
typedef int (*uls_strcmp_t)(uls_char_t* wrd1, int l_wrd1, uls_char_t* wrd2, int l_wrd2);

extern int uls_gettok_raw(uls_lex_t* uls);
extern int uls_gettok_bin(uls_lex_t* uls);

#ifdef __cplusplus
}
#endif

#endif 
